<script lang="ts" setup name="admin-role-tree">
import { rIndexPrivileges, userAuthInfo } from '@fl/api/iam-api'

const props = withDefaults(defineProps<{
    detail?: any
}>(), {
    detail: () => { },
})
const { detail } = toRefs(props)
const authList = ref<any>([])
const privileges = ref<any>([])

function getUserAuthInfo() {
    userAuthInfo().then((res) => {
        getRIndexPrivileges(res.org_id)
    })
}
getUserAuthInfo()

async function getRIndexPrivileges(data) {
    const params = {
        org_id: data,
    }
    rIndexPrivileges(params).then((res: any) => {
        res.forEach(((item: any) => {
            authList.value.push(item.code)
        }))

        authList.value.forEach((items) => {
            detail.value.privileges.forEach((itemss) => {
                if (items === itemss)
                    privileges.value.push(itemss)
            })
        })
    })
}
</script>

<template>
    <el-checkbox-group v-for="(item, index) in authList"
                       :key="index"
                       v-model="privileges"
                       privileges
    >
        <el-checkbox :value="item"
                     :label="item"
        >
            {{ item }}
        </el-checkbox>
    </el-checkbox-group>
</template>
